<?php

set_include_path(get_include_path() . PATH_SEPARATOR . "$_SERVER[DOCUMENT_ROOT]/ZendGdata-1.12.3/library");
require_once 'Zend/Loader.php';
//require_once 'ZendGdata-1.12.3/library/Zend/Loader.php';
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');

$service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient("hossain.eps@gmail.com", "021407016", $service);
$spreadsheetService = new Zend_Gdata_Spreadsheets($client);
//$feed = $spreadsheetService->getSpreadsheetFeed();
$spreadsheetKey = "0At3MtK6gNh_2dEluSk45cTgwRDVIZjRMdGJVUnduc1E";
$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
$query->setSpreadsheetKey($spreadsheetKey);
$feed = $spreadsheetService->getWorksheetFeed($query);
$worksheetId = 0;
foreach ($feed->entries as $entry) {
    if ($entry->getTitle()->getText() == "Sheet1") {
        $worksheetId = array_pop(explode("/", $entry->id->text));
        break;
    }
}
$query = new Zend_Gdata_Spreadsheets_ListQuery();
$query->setSpreadsheetKey($spreadsheetKey);
$query->setWorksheetId($worksheetId);
$query->setSpreadsheetQuery('name="Ashiq"');
//$query->setSpreadsheetQuery('name="Nazmul Hossain"');
$listFeed = $spreadsheetService->getListFeed($query);


echo "<pre>";
//print_r($listFeed->entries);
//echo $rowDataCount = count($listFeed->entries);
$old_row = null;
foreach ($listFeed->entries as $entry) {
    if ($entry instanceof Zend_Gdata_Spreadsheets_ListEntry) {
        $rowData = $entry->getCustom();
        $old_row = $entry;
        break;
        //echo $entry->getId();
        //echo "<br/>";
        foreach ($rowData as $customEntry) {
            echo $customEntry->getColumnName() . " = " . $customEntry->getText();
            echo "      ";
        }
    }
    echo "<br/>";
}

//$rowData = array("Name"=>"Ashiq","Email"=>"ashiqcse@gmail.com","Phone"=>"8801715509874","Address"=>"Dhaka");
//$insert_row = array();
//foreach ($rowData as $k => $v)
//    $insert_row[cleanKey($k)] = $v;
//$insertedListEntry = $spreadsheetService->insertRow($insert_row, $spreadsheetKey, $worksheetId);

/*
$oldRowData = array("Name"=>"Ashiq","Email"=>"ashiqcse@gmail.com","Phone"=>"8801715509874","Address"=>"Dhaka");
$old_row = array();
foreach ($oldRowData as $k => $v)
    $old_row[cleanKey($k)] = $v;
* */
//$newRowData = array("Name"=>"Hossain Nazmul","Email"=>"hossain.eps@gmail.com","Phone"=>"8801912537705","Address"=>"Adabor, Dhaka");
//$update_row = array();
//foreach ($newRowData as $k => $v)
//    $update_row[cleanKey($k)] = $v;
//
//$insertedListEntry = $spreadsheetService->updateRow($old_row, $update_row);
//
//function cleanKey($k) {
//    return strtolower(preg_replace('/[^A-Za-z0-9\-\.]+/', '', $k));
//}
//$spreadsheetService->deleteRow($old_row);
//echo "<pre>";
//print_r($feed);
 
?>
